﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DBUtility;
using System.Data;
using AccessModel;
using System.Data.SqlClient;

namespace AccessDAL
{
    public class UserDAL
    {        
        
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public List<User> GetAllUser()
        {
            string sql = "SELECT * FROM TAB_USER";
            List<User> userList = new List<User>();
            SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.connectionString, CommandType.Text, sql, null);
            while (reader.Read())
            {
                User user = new User();
                user.id = Convert.ToInt32(reader["id"].ToString());
                user.uNm = reader["uNm"].ToString();
                user.uPwd = reader["uPwd"].ToString();
                user.uDate = Convert.ToDateTime(reader["uDate"].ToString());
                userList.Add(user);
            }
            return userList;
        }

        public static User UserLogin(string uNm, string uPwd)
        {
            string sql = "SELECT * FROM TAB_USER WHERE UNM='" + uNm + "' AND UPWD='" + uPwd + "'";

            User user = new User();
            SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.connectionString, CommandType.Text, sql, null);
            while (reader.Read())
            {               
                user.id = Convert.ToInt32(reader["id"].ToString());
                user.uNm = reader["uNm"].ToString();
                user.uPwd = reader["uPwd"].ToString();
                user.uDate = Convert.ToDateTime(reader["uDate"].ToString());               
            }
            return user;
        }
    }
}
